package
{
	import com.suntech.lanq.*;
	
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	import king.loadProperties.LoadProperties;
	import king.loadProperties.Map;
	
	import mx.controls.Alert;

	public class Main
	{
		//消息调用常量
		public static const START_LOGIN:String="startLogin";
		
		private var conf:String="data/conf.pro";
		
		public static var IPArray:Array;
		public var localPort:int=6969;
		public var localIP:String="127.0.0.1";
		[Inject]
		public var udpSocket:UDPsocket;
		public function Main()
		{
		}
		
		[MessageHandler]
		public function login(s:String):void{
			//Alert.show(s);
			
			//暂时取IP地址列表中的第一个IP地址
			localIP=IPArray[0].toString();
			var a:Array=localIP.split(".");
			a[3]="255";
			//var broadcastIP:String=a.join(".");
			//Alert.show(a.join("."));
			//udpSocket=new UDPsocket();
			udpSocket.bind(localPort,localIP);
			var udpMessage:UDPMessage=new UDPMessage();
			udpMessage.type=UDPMessage.ONLINE;
			udpSocket.send(udpMessage,a.join("."),localPort);
		}
		
		public function init():void{
			//读取文件配置信息
//			var myFile:File = File.documentsDirectory.resolvePath("data/conf.pro");  
//			var myFileStream:FileStream = new FileStream();  
//			myFileStream.open(myFile, FileMode.UPDATE);  
//			myFileStream.position = 4000;   
//			trace(myFileStream.position); // 4000  
//			myFileStream.writeBytes(myByteArray, 0, 200);  
//			trace(myFileStream.position); // 4200       
			LoadProperties.getInstance(conf).getMap(initMap); 
			
			function initMap(map:Map):void{
				
				trace("map："+map);
				
				Alert.show("河北省："+map.get("firstRun"));
			}
		}

	}
}
